package com.oraycn.esbasic.views;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import com.oraycn.esbasic.R;


public class CommonDialog extends Dialog {
    private Context mContext;
    private Window dialogWindow;

    public CommonDialog(@NonNull Context context,View view) {
        super(context, R.style.ActionSheetDialogStyle);
        this.initView(context,view);
    }

    public CommonDialog(@NonNull Context context, int themeResId,View view) {
        super(context, themeResId);
        this.initView(context,view);
    }
    private void initView(Context context, View view)
    {
        this.mContext=context;
//        View view =  LayoutInflater.from(this.mContext).inflate(R.layout.action_sheet_dialog,null);
//
//        //将布局设置给Dialog 
        this.setContentView(view);
        //获取当前Activity所在的窗体
        dialogWindow = this.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        //获得窗体的属性
        lp.width=WindowManager.LayoutParams.MATCH_PARENT;
        lp.y = 20;//设置Dialog距离底部的距离
        //将属性设置给窗体
        dialogWindow.setAttributes(lp);
    }

    /**
     * 设置窗体属性 （如宽高、从底部显示）
     * @param lp
     */
    public void setWindowAttributes(WindowManager.LayoutParams lp)
    {
        dialogWindow.setAttributes(lp);
    }

}
